{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Java\n",
    "\n",
    "Java is the mother of all JVM languages, first released in 1995 after years of development by Sun Microsystems.  BeakerX uses [OpenJDK](http://openjdk.java.net/) for Java and all the kernels.\n",
    "\n",
    "BeakerX supports Java cells that define classes, which can be used by other JVM based cells.\n",
    "One cell is equivalent to a Java compilation unit and can contain a single class, or a sequence of statements."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "package test.beaker;\n",
    "\n",
    "import java.util.Date;\n",
    "import java.text.SimpleDateFormat;\n",
    "\n",
    "public class BeakerTest {\n",
    "  private Date _date;\n",
    "  private SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mmZ\");\n",
    "  \n",
    "  public BeakerTest() {\n",
    "    _date = new Date();\n",
    "  }\n",
    "\n",
    "  public String getDateTxt() {\n",
    "    return \"Today:\" + sdf.format(_date);\n",
    "  }\n",
    "\n",
    "  public String getDateUpperCaseTxt() {\n",
    "    return getDateTxt().toUpperCase();\n",
    "  }\n",
    "\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "package test.beaker;\n",
    "\n",
    "BeakerTest bt = new BeakerTest();\n",
    "return bt.getDateTxt();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import java.util.List;\n",
    "import java.util.ArrayList;\n",
    "import com.twosigma.beakerx.chart.xychart.Plot;\n",
    "import com.twosigma.beakerx.chart.xychart.plotitem.*;\n",
    "import com.twosigma.beakerx.chart.Color;\n",
    "\n",
    "Plot p = new Plot();\n",
    "\n",
    "p.setTitle(\"this is a Java plot\");\n",
    "\n",
    "Bars b = new Bars();\n",
    "\n",
    "List<Number> yList = new ArrayList<Number>();\n",
    "yList.add(2);\n",
    "yList.add(5);\n",
    "yList.add(4);\n",
    "yList.add(8);\n",
    "\n",
    "b.setY(yList);\n",
    "b.setColor(Color.blue);\n",
    "b.setWidth(0.5);\n",
    "\n",
    "p.add(b);\n",
    "  \n",
    "return p;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "package test.beaker;\n",
    "interface DateGetter {\n",
    "   public String getDateTxt();\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "package test.beaker;\n",
    "public class DG2 extends BeakerTest implements DateGetter {\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using the classpath to load a jar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%classpath add jar ../resources/jar/BeakerXClasspathTest.jar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "System.out.println(\"The Groovy working folder is :\");\n",
    "System.out.println(java.nio.file.Paths.get(\".\").toAbsolutePath().normalize().toString());\n",
    "System.out.println(\"BeakerXClasspathTest.jar exists in this folder\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import com.beaker.BeakerXClasspathTest;\n",
    "\n",
    "BeakerXClasspathTest t = new BeakerXClasspathTest();\n",
    "System.out.println(com.beaker.BeakerXClasspathTest.staticTest);\n",
    "System.out.println(t.getObjectTest());"
   ]
  }
 ],
 "metadata": {
  "beakerx_kernel_parameters": {},
  "kernelspec": {
   "display_name": "Java",
   "language": "java",
   "name": "java"
  },
  "language_info": {
   "codemirror_mode": "text/x-java",
   "file_extension": ".java",
   "mimetype": "",
   "name": "Java",
   "nbconverter_exporter": "",
   "version": "1.8.0_121"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
